/*
 * Created on May 27, 2004
 */
//package BallBounce;

/**
 * @author he
 */
import java.awt.*;
import javax.swing.*;

public class BallBounce4 /*ans bl*/extends JApplet /*ans ab*/{
	int x = 100;
	int y = 150;
	int xVelocity = 1;
	int yVelocity = 1;
	boolean drawOval = true;
	
	public void paint(Graphics g)
	{
		for(int i = 0; i < 2000; i++)
		{
			g.setColor(Color.white);
			g.fillOval(x,y,30,30);
			
			x += xVelocity;
			y += yVelocity;

			//Smashing the right wall
			if (x > 350) {
				drawOval = false;
				for(int h = 0; h < 50; h++) {
					g.setColor(Color.blue);
					g.fillOval((x+(h/2)),y,(30-(h/2)),30);
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval((x+(h/2)),y,(30-(h/2)),30);
				}
				xVelocity = -xVelocity;
				for(int h = 50; h > 0; h--) {
					g.setColor(Color.blue);
					g.fillOval((x+(h/2)),y,(30-(h/2)),30);
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval((x+(h/2)),y,(30-(h/2)),30);
				}
			}
			//Smashing the left wall
			if (x < 50) {
				drawOval = false;
				for(int h = 0; h < 50; h++) {
					g.setColor(Color.blue);
					g.fillOval(x,y,(30-(h/2)),30);
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,y,(30-(h/2)),30);
				}
				xVelocity = -xVelocity;
				for(int h = 50; h > 0; h--) {
					g.setColor(Color.blue);
					g.fillOval(x,y,(30-(h/2)),30);
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,y,(30-(h/2)),30);
				}
			}
			
			//Smashing the bottom wall
			if (y > 250)
			{
				drawOval = false;
				for(int k = 0; k < 50; k++) {
					g.setColor(Color.orange);
					g.fillOval(x,(y+(k/2)),30,(30-(k/2)));
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,(y+(k/2)),30,(30-(k/2)));
				}
				yVelocity = -yVelocity;
				for(int k = 50; k > 0; k--) {
					g.setColor(Color.orange);
					g.fillOval(x,(y+(k/2)),30,(30-(k/2)));
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,(y+(k/2)),30,(30-(k/2)));
				}
			}
			//Smashing the tap wall
			if (y < 50)
			{
				drawOval = false;
				for(int k = 0; k < 50; k++) {
					g.setColor(Color.orange);
					g.fillOval(x,y,30,(30-(k/2)));
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,y,30,(30-(k/2)));
				}
				yVelocity = -yVelocity;
				for(int k = 50; k > 0; k--) {
					g.setColor(Color.orange);
					g.fillOval(x,y,30,(30-(k/2)));
					
					for (int j = 0; j < 2000000; j++);
					
					g.setColor(Color.white);
					g.fillOval(x,y,30,(30-(k/2)));
				}
			}
			if (drawOval) {
				int check = i%100;
				if(check <= 50) g.setColor(Color.red);
				else if(check >= 51) g.setColor(Color.green);
				
				g.fillOval(x, y, 30, 30);
				for (int j = 0; j < 2000000; j++);
			}
			drawOval = true;
		}
		System.exit(0);
	}
}
